$(function () {
     var userInfo = LoginStatus();
     $.ajax({
        type: 'get', // 提交方式 get/post
        url:services+"/user/prop/educationLevel/list",// 需要提交的 url
        async:false,
        // contentType:"application/json;charset=utf-8",
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        success: function(res) {
            var obj = JSON.parse(res);
            if(obj.code==0){
                data = obj.data;
                var educationLevel = "";
                var html = "";
                if($.cookie("experienceEducations")){
                    var experienceEducations = $.cookie("experienceEducations");
                    var obj = JSON.parse(experienceEducations)
                    educationLevel = obj[0].educationLevel
                }
                $.each(data, function (index, item) {
                    if (educationLevel != null && educationLevel != '' && educationLevel == item.id) {
                        
                        html += '<option value="'+item.id+'" selected>'+item.name+'</option>';
                    } else {
                        html += '<option value="'+item.id+'">'+item.name+'</option>';
                    }
                })
                $("#educationLevels").append(html);
            }
        },
    })
    //判断是否存在cookie
    if($.cookie("experienceEducations")){
        var experienceEducations = $.cookie("experienceEducations");
        var obj = JSON.parse(experienceEducations)
        $("input[name='school']").val(obj[0].school)
        $("input[name='profession']").val(obj[0].profession)
        //职位
        $("input[name='admissionTime").val(obj[0].admissionTime)
        //描述
        $("input[name='graduationTime']").val(obj[0].graduationTime)

    }

    useLayUI();
    $("#Submitbtn").click(function(){
        var experienceEducations = [];
        var school = $("input[name='school']").val();
        if(school==null||school==""){
            layerMsg("学校不为空");
            return false;
        }
        var educationLevel = $("select[name='educationLevel']").val();
        if(educationLevel==null||educationLevel==""){
            layerMsg("学历不为空");
            return false;
        }
        var profession=$("input[name='profession']").val();
        if(profession==null||profession==""){
            layerMsg("专业不为空");
            return false;
        }
        var admissionTime=$("input[name='admissionTime']").val()
        if(admissionTime==null||admissionTime==""){
            layerMsg("就读时间不为空");
            return false;
        }
        var graduationTime=$("input[name='graduationTime']").val()
        if(graduationTime==null||graduationTime==""){
            layerMsg("就读时间不为空");
            return false;
        }
        var jsondata = {'school':school,
        'educationLevel':educationLevel
        ,"profession":profession
        ,"admissionTime":admissionTime  //注意时间格式
        ,"graduationTime":graduationTime
        }
        experienceEducations.push(jsondata)
        $.cookie('experienceEducations',JSON.stringify(experienceEducations));
        layerMsg("添加成功")
        setTimeout(function() {
            window.location.href="register-intention.html" ;
        },3000);
        // console.log(experienceEducations)
        // var experienceWork = $.cookie('experienceWork');
        // console.log(experienceWork)
        // if(experienceWork==null||experienceWork==""){
        //     experienceWork=[];
        // }
    });
})